#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
THN DATA ABSTRACTION LAYER version 1

Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

This library is dual-licensed.
  + For commercial software, please obtain a commercial license from THN Solutions LLC.

  + For free software, this library is licensed under GPL version 3. A summary of GPLv3 is
    listed below. You should also find a copy of GPLv3 as file License_GPLv3.txt included
	with the source-code files.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License version 3 as published by
    the Free Software Foundation  of the License.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#endregion

#region Using directives
using System;
using System.Data;
#endregion

namespace Thn.Data.Mapping
{
    /// <summary>
    /// Specifies the name of Column a class's attribute is mapped to
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public class ColumnAttribute : Attribute
    {
        #region Name
        private string mName = "";
        /// <summary>
        /// Gets/Sets the Column name
        /// </summary>
        public string Name
        {
            get { return mName; }
            set { mName = value; }
        }
        #endregion

        #region DbTypeSpecified
        private bool mDbTypeSpecified;
        /// <summary>
        /// Gets whether this map needs a user-specified DbType or just let the dialect handles it
        /// </summary>
        public bool DbTypeSpecified
        {
            get { return mDbTypeSpecified; }
        }
        #endregion

        #region Type
        private DbType mType;
        /// <summary>
        /// Gets/Sets data type. If not set, infer from dialect
        /// </summary>
        public DbType Type
        {
            get { return mType; }
            set 
            {
                mType = value;
                mDbTypeSpecified = true;
            }
        }
        #endregion

        #region Size
        private int mSize;
        /// <summary>
        /// Gets/Sets length
        /// </summary>
        public int Size
        {
            get { return mSize; }
            set { mSize = value; }
        }
        #endregion

        #region Required
        private bool mRequired = true;
        /// <summary>
        /// Gets/Sets whether this field can be null
        /// </summary>
        public bool Required
        {
            get { return mRequired; }
            set { mRequired = value; }
        }
        #endregion
			
        #region Constructors
        /// <summary>
        /// Empty constructor
        /// </summary>
        public ColumnAttribute() { }

        /// <summary>
        /// Brief constructor
        /// </summary>
        /// <param name="columnName">Name of column this class is mapped to</param>
        public ColumnAttribute(string columnName)
        {
            mName = columnName;            
        }

        /// <summary>
        /// Full constructor
        /// </summary>
        /// <param name="columnName">Name of column this class is mapped to</param>
        /// <param name="dataType">Type of underlying data</param>
        /// <param name="required">Whether this field can be null or empty</param>
        public ColumnAttribute(string columnName, DbType dataType, bool required)
        {
            mName = columnName;
            mType = dataType;
            mRequired = required;
        }
        #endregion
    }
}
